package com.leetcode.LeetCode精选TOP面试题;

/**
 * @author 覃国强
 * @date 2022-07-06 11:26
 */
public class 题库_0190_颠倒二进制位 {

  public static void main(String[] args) {
    int n = 43261596;
    System.out.println(new Solution().reverseBits(n));
  }

  static
  public class Solution {
    // you need treat n as an unsigned value
    public int reverseBits(int n) {
      if (n == 0) {
        return n;
      }
      int answer = 0;
      for (int i = 0; i < 32; ++i) {
        int num = n & 1;
        answer = (answer << 1 | num);
        n >>>= 1;
      }
      return answer;
    }
  }

}
